﻿Module GameData

    Public Sub Init()

        LoadCharacters()

    End Sub

    Public Structure Row_TBL_CHARACTER
        Dim ID_CHARACTER As Int64
        Dim ID_LOGIN As Int64
        Dim CharacterName As String
        Dim IsDeleted As Boolean
        Dim CreatedAt As String
        Dim LastLoginAt As String
        Dim Job As CharacterJobs
        Dim Gender As Gender
        Dim StoragePassMD5 As String
        Dim Hair As Byte
        Dim HairColor As Integer
        Dim ShowHelmet As Boolean

        Dim NeedsSQLUpdate As Boolean

    End Structure

    Private TBL_CHARACTER As SortedDictionary(Of Int64, Row_TBL_CHARACTER)

    Private Sub LoadCharacters()

        Dim sSql = "SELECT * FROM TBL_CHARACTER"
        Dim rows As ArrayList = DB.GameDB.ExecuteQuery(sSql)

        If rows Is Nothing Then Exit Sub
        If rows.Count = 0 Then Exit Sub

        For i As Integer = 0 To rows.Count - 1

            Dim Row As Row_TBL_CHARACTER

            Row.ID_CHARACTER = rows(i)("ID_CHARACTER")
            Row.ID_LOGIN = rows(i)("ID_LOGIN")
            Row.CharacterName = rows(i)("STR_NAME")
            Row.IsDeleted = rows(i)("BOOL_DELETED")
            Row.CreatedAt = rows(i)("STR_CREATED")
            Row.LastLoginAt = rows(i)("STR_LASTLOGIN")
            Row.Job = rows(i)("BYTE_JOB")
            Row.Gender = rows(i)("BYTE_SEX")
            Row.StoragePassMD5 = rows(i)("STR_STORAGEPASSMD5")
            Row.Hair = rows(i)("BYTE_HAIR")
            Row.HairColor = rows(i)("BYTE_HAIRCOL")
            Row.ShowHelmet = rows(i)("BOOL_SHOWHELMET")

            Row.NeedsSQLUpdate = False

            TBL_CHARACTER.Add(Row.ID_CHARACTER, Row)

        Next

    End Sub

End Module
